home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / PDOS / TN.PDOS.021 < prev    next >
Encoding:
Text File  |  1990-04-03  |  22.0 KB  |  431 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. ProDOS 8
  7. #21:    Identifying ProDOS Devices
  8.  
  9. Revised by:    Dave Lyons & Matt Deatherage                        March 1990
  10. Written by:    Matt Deatherage & Dan Strnad                     November 1988
  11.  
  12. This Technical Note describes how to identify ProDOS devices and their 
  13. characteristics given the ProDOS unit number.  This scheme should only be used 
  14. under ProDOS 8.
  15. Changes since January 1990:  Modified AppleTalk call code for compatibility 
  16. with ProDOS 8 versions earlier than 1.5 and network-booted version 1.4.
  17. _____________________________________________________________________________
  18.  
  19. There are various reasons why an application would want to identify ProDOS 
  20. devices.  Although ProDOS itself takes great pains to treat all devices 
  21. equally, it has internal drivers for two types of devices:  Disk II drives and 
  22. the /RAM drive provided on 128K or greater machines.  Because all devices 
  23. really are not equal (i.e., some cannot format while others are read-only, 
  24. etc.), a developer may need to know how to identify a ProDOS device.
  25.  
  26. Although the question of how much identification is subjective for each 
  27. developer, ProDOS 8 offers a fair level of identification; the only devices 
  28. which cannot be conclusively identified are those devices with RAM-based 
  29. drivers, and they could be anything.  The vast majority of ProDOS devices can 
  30. be identified, however, so you could prompt the user to insert a disk in 
  31. UniDisk 3.5 #2, instead of Slot 2, Drive 2, which could be confusing if the 
  32. user has a IIc or IIGS.
  33.  
  34. Note that for the majority of applications, this level of identification is 
  35. unnecessary.  Most applications simply prompt the user to insert a disk by its 
  36. name, and the user can place it in any drive which is capable of working with 
  37. the media of the disk.  You should avoid requiring a certain disk to be in a 
  38. specific drive since doing so defeats much of the device-independence which 
  39. gives ProDOS 8 its strength.
  40.  
  41. When you do need to identify a device (i.e., if you need to format media in a 
  42. Disk II or /RAM device), however, the process is fairly straightforward.  This 
  43. process consists of a series of tests, any one of which could end with a 
  44. conclusive device identification.  It is not possible to look at a single ID 
  45. byte to determine a particular device type.  You may determine rather quickly 
  46. that a device is a SmartPort device, or you may go all the way through the 
  47. procedure to identify a third-party network device.  For those developers who 
  48. absolutely must identify devices, DTS presents the following discussion.
  49.  
  50.  
  51. Isn't There Some Kind of "ID Nibble?"
  52.  
  53. ProDOS 8 does not support an "ID nibble."  Section 5.2.4 of the ProDOS 8 
  54. Technical Reference Manual states that the low nibble of each unit number in 
  55. the device list "is a device identification:  0 = Disk II, 4 = Profile, 
  56. $F = /RAM."
  57.  
  58.  
  59. When ProDOS 8 finds a "smart" ProDOS block device while doing its search of 
  60. the slots and ports, it copies the high nibble of $CnFE (where n is the slot 
  61. number) into the low nibble of the unit number in the global page.  The low 
  62. nibble then has the following definition:
  63.  
  64.     Bit 3:    Medium is removable
  65.     Bit 2:    Device is interruptible
  66.     Bit 1-0:  Number of volumes on the device (minus one)
  67.  
  68. As you can see, it is quite easy for the second definition to produce one of 
  69. the original values (e.g., 0, 4, or $F) in the same nibble for completely 
  70. different reasons.  You should ignore the low nibble in the unit number in the 
  71. global page when identifying devices since the first definition is 
  72. insufficient to uniquely identify devices and the second definition contains 
  73. no information to specifically identify devices.  Once you do identify a 
  74. ProDOS block device, however, you may look at $CnFE to obtain the information 
  75. in the second definition above, as well as information on reading, writing, 
  76. formatting, and status availability.
  77.  
  78. When identifying ProDOS devices, start with a list of unit numbers for all 
  79. currently installed disk devices.  As you progress through the identification 
  80. process, you identify some devices immediately, while others must wait until 
  81. the end of the process for identification.
  82.  
  83.  
  84. Starting with the Unit Number
  85.  
  86. ProDOS unit numbers (unit_number) are bytes where the bits are arranged in the 
  87. pattern DSSS0000, where D = 0 for drive one and D = 1 for drive two, SSS is a 
  88. three-bit integer with values from one through seven indicating the device 
  89. slot number (zero is not a valid slot number), and the low nibble is ignored.
  90.  
  91. To obtain a list of the unit numbers for all currently installed ProDOS disk 
  92. devices, you can perform a ProDOS MLI ON_LINE call with a unit number of $00.  
  93. This call returns a unit number and a volume name for every device in the 
  94. device list.  ProDOS stores the length of the volume name in the low nibble of 
  95. the unit number which ON_LINE returns; if an error occurs, the low nibble 
  96. contains $0 and the byte immediately following the unit number contains an 
  97. error code.  For more information on the ON_LINE call, see section 4.4.6 of 
  98. the ProDOS 8 Technical Reference Manual.  A more detailed discussion of the 
  99. error codes follows later in this Note.
  100.  
  101. To identify the devices in the device list, you need to know in which physical 
  102. slot the hardware resides, so you can look at the slot I/O ROM space and check 
  103. the device's identification bytes.  Note that the slot-number portion of the 
  104. unit number does not always represent the physical slot of the device, rather, 
  105. it sometimes represents the logical slot where you can find the address of the 
  106. device's driver entry point in the ProDOS global page.  For example, if a 
  107. SmartPort device interface in slot 5 has more than two connected devices, the 
  108. third and fourth devices are mapped to slot 2; this mapping gives these two 
  109. devices unit numbers of $20 and $A0 respectively, but the device's driver 
  110. entry point is still in the $C5xx address space.
  111.  
  112. ProDOS 8 Technical Note #20, Mirrored Devices and SmartPort, discusses this 
  113. kind of mapping in detail.  It also presents a code example which gives you 
  114. the correct device-driver entry point (from the global page) given the unit 
  115. number as input.  Here is the code example from that Note for your benefit.  
  116. It assumes the unit_number is in the accumulator.
  117.  
  118.  
  119. devcnt      equ    $BF31
  120. devlst      equ    $BF32
  121. devadr      equ    $BF10
  122. devget      sta    unitno      ; store for later compare instruction
  123.             ldx    devcnt      ; get count-1 from $BF31
  124. devloop     lda    devlst,x    ; get entry in list
  125.             and    #$F0        ; mask off low nibble
  126. devcomp     cmp    unitno      ; compare to the unit_number we filled in
  127.             beq    goodnum     ;
  128.             dex
  129.             bpl    devloop     ; loop again if still less than $80
  130.             bmi    badunitno   ; error: bad unit number
  131. goodnum     lda    unitno      ; get good copy of unit_number
  132.             lsr    a           ; divide it by 8
  133.             lsr    a           ; (not sixteen because devadr entries are
  134.             lsr    a           ; two bytes wide)
  135.             tax
  136.             lda    devadr,x    ; low byte of device driver address
  137.             sta    addr
  138.             lda    devadr+1,x  ; high byte of device driver address
  139.             sta    addr+1
  140.             rts
  141. addr        dw     0           ; address will be filled in here by goodnum
  142. unitno      dfb    0           ; unit number storage
  143.  
  144. Warning:    Attempting to construct the device-driver entry point from 
  145.             the unit number is very dangerous.  Always use the technique 
  146.             presented above.
  147.  
  148.  
  149. Network Volumes
  150.  
  151. AppleTalk volumes present a special problem to some developers since they 
  152. appear as "phantom devices," or devices which do not always have a device 
  153. driver installed in the ProDOS global page.  Fortunately, the ProDOS Filing 
  154. Interface (PFI) to AppleTalk provides a way to identify network volumes 
  155. through an MLI call.  The ProDOS Filing Interface call FIListSessions is used 
  156. to retrieve a list of the current sessions being maintained through PFI and 
  157. any volumes mounted for those sessions.
  158.  
  159. In the following example, note the check for ProDOS 8 version 1.5 or higher, 
  160. and the simulation of a bad command error under older versions (the $42 call 
  161. under ProDOS 8 version 1.4 always crashes if ProDOS was launched from a local 
  162. disk):
  163.  
  164. Network     LDA    #$04        ;require at least ProDOS 8 1.4
  165.             CMP    $BFFF       ;KVERSION (ProDOS 8 version)
  166.             BEQ    MoreNetwork ;have to check further
  167.             LDA    #$01        ;simulate bad command error
  168.             BCS    ERROR       ;if 3 or less, no possibility of network
  169.             BCC    NetCall     ;otherwise, try the network call
  170.  
  171. MoreNetwork LDA    $BF02       ;high byte of the MLI entry point
  172.             AND    #$F0        ;strip off the low nibble
  173.             CMP    #$C0        ;is the entry into the $Cn00 space?
  174.             BEQ    NetCall     ;yes, so try AppleTalk
  175.             LDA    #$01
  176.             SEC
  177.             BCS    ERROR       ;simulate bad command error
  178.  
  179. NetCall     JSR    $BF00        ;ProDOS MLI
  180.             DFB    $42          ;AppleTalk command number
  181.             DW     ParamAddr    ;Address of Parameter Table
  182.             BCS    ERROR        ;error occurred
  183.  
  184. ParamAddr   DFB    $00          ;Async Flag (0 means synchronous only)
  185.                                 ;note there is no parameter count
  186.             DFB    $2F          ;command for FIListSessions
  187.             DW     $0000        ;AppleTalk Result Code returned here
  188.             DW     BufLength    ;length of the buffer supplied
  189.             DW     BufPointer   ;low word of pointer to buffer
  190.             DW     $0000        ;high word of pointer to buffer
  191.                                 ;(THIS WILL NOT BE ZERO IF THE BUFFER IS
  192.                                 ;NOT IN BANK ZERO!)
  193.             DFB    $00          ;Number of entries returned here
  194.  
  195. If the FIListSessions call fails with a bad command error ($01), then 
  196. AppleShare is not installed; therefore, there are no networks volumes mounted.  
  197. If there is a network error, the accumulator contains $88 (Network Error), and 
  198. the result code in the parameter block contains the specific error code.  The 
  199. list of current sessions is placed into the buffer (at the address BufPointer 
  200. in the example above), but if the buffer is not large enough to hold the list, 
  201. it retains the maximum number of current sessions possible and returns an 
  202. error with a result code of $0A0B (Buffer Too Small).  The buffer format is as 
  203. follows:
  204.  
  205. SesnRef     DFB    $00          ;Sessions Reference number (result)
  206. UnitNum     DFB    $00          ;Unit Number (result)
  207. VolName     DS     28           ;28 byte space for Volume Name
  208.                                 ;(starts with a length byte)
  209. VolumeID    DW    $0000         ;Volume ID (result)
  210.  
  211. This list is repeated for every volume mounted for each session (the number is 
  212. placed into the last byte of the parameter list you passed to the ProDOS MLI).  
  213. For example, if there are two volumes mounted for session one, then session 
  214. one is listed two times.  The UnitNum field contains the slot and drive number 
  215. in unit-number format, and note that bit zero of this byte is set if the 
  216. volume is a user volume (i.e., it contains a special "users" folder).  This 
  217. distinction is unimportant for identifying a ProDOS device as a network 
  218. pseudo-device, but it is necessary for applications which need to know the 
  219. location of the user volume.  Note that if you mount two servers or more with 
  220. each having its own user volume, the user volume found first in the list 
  221. (scanned top to bottom) returned by FIListSessions specifies the user volume 
  222. that an application should use.  See the AppleShare Programmer's Guide for the 
  223. Apple IIGS for more information on programming for network volumes.
  224.  
  225. If you keep a list of all unit numbers returned by the ON_LINE call and mark 
  226. each one "identified" as you identify it, keep in mind that the unit numbers 
  227. returned by FIListSessions and ON_LINE have different low nibbles which should 
  228. be masked off before you make any comparisons.
  229.  
  230. Note:  You should mark the network volumes as identified and not try to 
  231.        identify them further with the following methods.
  232.  
  233.  
  234. What Slot is it Really In?
  235.  
  236. Once you have the address of the device driver's entry point and know that the 
  237. device is not a network pseudo-device, you can determine in what physical slot 
  238. the device resides.  If the high byte of the device driver's entry point is of 
  239. the form $Cn, then n is the physical slot number of the device.  A SmartPort 
  240. device mirrored to slot 2 has a device driver address of $C5xx, giving 5 as 
  241. the physical slot number.
  242.  
  243.  
  244. If the high byte of the device driver entry point is not of the form $Cn, then 
  245. there are three other possibilities:
  246.  
  247.   o  The device is a Disk II with driver code inside ProDOS.
  248.   o  The device is either /RAM with driver code inside ProDOS or a 
  249.      third-party auxiliary-slot RAM disk device with driver code 
  250.      installed somewhere in memory.
  251.   o  The device is not a RAM disk but has a RAM-based device driver, 
  252.      like a third-party network device.
  253.  
  254. Auxiliary-slot RAM disks are identified by convention.  Any device in slot 3, 
  255. drive 2 (unit number $B0) is assumed to be an auxiliary-slot RAM disk since 
  256. ProDOS 8 does not recognize any card which is not an 80-column card in slot 3 
  257. (see ProDOS 8 Technical Note #15, How ProDOS 8 Treats Slot 3).  There is a 
  258. chance that some other kind of device could be installed with unit number $B0, 
  259. but it is not likely.
  260.  
  261. To identify various kinds of auxiliary-slot RAM disks, you must obtain the 
  262. unit number from the ProDOS global page.  The list of unit numbers starts at 
  263. $BF32 (DEVLST) and is preceded by the number of unit numbers minus one 
  264. (DEVCNT, at $BF31).  You should search through this list until you find a unit 
  265. number in the form $Bx; if the unit number is $B3, $B7, $BB, or $BF, you can 
  266. assume the device to be an auxiliary-slot RAM disk which uses the auxiliary 
  267. 64K bank of memory present in a 128K Apple IIe or IIc, or a IIGS.  If the unit 
  268. number is one of the four listed above, you must remove this device to safely 
  269. access memory in the auxiliary 64K bank, but if the unit number is not one of 
  270. the four listed above, you can assume the device to be an auxiliary-slot RAM 
  271. disk which does not use the normal bank of auxiliary memory.  (Some third-
  272. party auxiliary-slot cards contain more than one 64K auxiliary bank; the 
  273. normal use of this memory is as a RAM disk.  If the RAM-based driver for this 
  274. kind of card does not use the normal auxiliary 64K bank for storage, it should 
  275. have a unit number other than one of the four listed above.)  If the unit 
  276. number is not one of the four listed above, you may safely access the 
  277. auxiliary bank of memory without first removing this device.
  278.  
  279. Section 5.2.2.3 of the ProDOS 8 Technical Reference Manual contains a routine 
  280. which disconnects the appropriate RAM disk devices in slot 3, drive 2, without 
  281. removing those drivers which do not use that bank, to allow use of the 
  282. auxiliary 64K bank.
  283.  
  284. Note:  Previous information from Apple indicated that /RAM could be 
  285.        distinguished from third-party RAM disks by a driver address of 
  286.        $FF00.  Although the address has not changed, some third-party 
  287.        drivers may have addresses of $FF00 as well, although this is not 
  288.        supported.  /RAM always has a driver address of $FF00 and unit 
  289.        number $BF, although any third-party RAM disk could install itself 
  290.        with similar attributes.
  291.  
  292. For Disk II devices, the three-bit slot number portion of the unit_number is 
  293. always the physical slot number.  Disk II devices can never be mirrored to 
  294. another slot (the Disk II driver does not support it); therefore, it is in the 
  295. physical slot represented in the unit number which ProDOS assigns when it 
  296. boots.
  297.  
  298. If the high byte of the device driver's entry point is not of the form $Cn, 
  299. then you should assume that the slot number is the value SSS in the unit 
  300. number (this is equivalent to assuming the device is a Disk II) for the next 
  301. step, which is checking the I/O space for identification bytes.
  302.  
  303.  
  304. What to Do With the Slot Number
  305.  
  306. Once you have the slot number, you can look at the slot I/O ROM space to 
  307. determine the kind of device it is.  As described in the ProDOS 8 Technical 
  308. Reference Manual, ProDOS looks for the following ID bytes in ROM to determine 
  309. if a ProDOS device is in a slot:
  310.  
  311.     $Cn01 = $20
  312.     $Cn03 = $00
  313.     $Cn05 = $03
  314.  
  315. If you use the slot number, n, you obtained above, and the three values listed 
  316. above are not present, then the device has a RAM-based driver and cannot 
  317. further be identified.
  318.  
  319. If the three values previously discussed are present, then examination of 
  320. $CnFF gives more information.  If $CnFF = $00, the device is a Disk II.  If 
  321. $CnFF is any value other than $00 or $FF ($FF signifies a 13-sector Disk II, 
  322. which ProDOS does not support), the device is a ProDOS block device.
  323.  
  324. For ProDOS block devices, the byte at $CnFE contains several flags which 
  325. further identify the device; these flags are discussed in section 6.3.1 of the 
  326. ProDOS 8 Technical Reference Manual.
  327.  
  328.  
  329. SmartPort Devices
  330.  
  331. Many of Apple's ProDOS block devices follow the SmartPort firmware interface.  
  332. Through SmartPort, you can further identify devices.  Existing SmartPort 
  333. devices include SCSI hard disks, 3.5" disk drives and CD-ROM drives, with many 
  334. more possible device types.
  335.  
  336. If $Cn07 = $00, then the device is a SmartPort device, and you can then make a 
  337. SmartPort call to get more information about the device, including a device 
  338. type and subtype.  The SmartPort entry point is three bytes beyond the ProDOS 
  339. block device entry point, which you already determined.  The method for making 
  340. SmartPort calls is outlined in the Apple IIc Technical Reference Manual, 
  341. Second Edition and the Apple IIGS Firmware Reference.
  342.  
  343. The most useful SmartPort call to make for device identification is the STATUS 
  344. call with statcode = 3 for Return Device Information Block (DIB).  This call 
  345. returns the ASCII name of the device, a device type and subtype, as well as 
  346. the size of the device.  Some SmartPort device types and subtypes are listed 
  347. in the referenced manuals, with a more complete list located in the Apple IIGS 
  348. Firmware Reference.  A list containing SmartPort device types only is provided 
  349. in SmartPort Technical Note #4, SmartPort Device Types.
  350.  
  351.  
  352. RAM-Based Drivers
  353.  
  354. One fork of the identification tree comes to an end at this point.  If the 
  355. high byte of the device driver entry point was not $Cn and the device was not 
  356. /RAM, you assumed it was a Disk II and used the slot number portion of the 
  357. unit number to examine the slot ROM space.  If the ROM space for that slot 
  358. number does not match the three ProDOS block device ID bytes, it cannot be a 
  359. Disk II.  Having ruled out other possibilities, it must be a device installed 
  360. after ProDOS finished building its device table.  Perhaps it is a third-party 
  361. RAM disk driver or maybe a driver for an older card which does not match the 
  362. ProDOS block device ID bytes.
  363.  
  364. Whatever the function of the driver, you can identify it no further.  It quite 
  365. literally could be any kind of device at all, and with neither slot ROM space 
  366. to identify nor a standard location to compare the device driver entry point 
  367. against, the best you can do is consider it a "generic device" and go on.
  368.  
  369.  
  370. But Is It Connected and Can I Read From It?
  371.  
  372. Just because a ProDOS device is in the table does not mean it is ready to be 
  373. used.  There is always the possibility that the drive has no media in it.  
  374. Back in the beginning, you made an ON_LINE call with a unit number of $00.  If 
  375. the volume name of a disk in that device could not be read, or another error 
  376. occurred, ProDOS 8 would return the error code in the ON_LINE buffer 
  377. immediately following the unit number.  Those errors possible include:
  378.  
  379.     $27    I/O error
  380.     $28    No Device Connected
  381.     $2B    Write Protected
  382.     $2F    Device off-line
  383.     $45    Volume directory not found
  384.     $52    Not a ProDOS disk
  385.     $55    Volume Control Block full
  386.     $56    Bad buffer address
  387.     $57    Duplicate volume on-line
  388.  
  389. Note that error $2F is not listed in the ProDOS 8 Technical Reference Manual.
  390.  
  391. By convention, you interpret I/O error to mean the disk in the drive is either 
  392. damaged or blank (not formatted).  You interpret Device off-line to mean that 
  393. there is no disk in the drive.  You interpret No Device Connected to mean the 
  394. drive really does not exist (for example, asking for status on a second Disk 
  395. II when only one is connected).
  396.  
  397. If no error occurred for a unit number in the ON_LINE call (the low nibble of 
  398. the unit number is not zero), the volume name of the disk in the drive follows 
  399. the unit number.
  400.  
  401.  
  402. Things To Avoid
  403.  
  404. The ProDOS device-level STATUS call generally returns the number of blocks on 
  405. a device.  Applications should not try to identify 3.5" drives by doing a 
  406. ProDOS or SmartPort STATUS call and comparing the number of blocks to 800 or 
  407. 1,600.  The correct way to identify a 3.5" drive is by the Type field in a 
  408. SmartPort STATUS call.
  409.  
  410. Don't assume the characteristics of a device just because it is in a certain 
  411. slot.  For example, be prepared to deal with 5.25" disk drives in slots other 
  412. than 6.  Don't assume that slot 6 is associated with block devices at all--
  413. there could be a printer card installed.
  414.  
  415. Avoid reinstalling /RAM when your application finds it removed.  If you remove 
  416. /RAM, you should reinstall it when you're done with the extra memory; however, 
  417. if your application finds /RAM already gone, you do not have the right to just 
  418. reinstall it.  A driver of some kind may be installed in auxiliary memory, and 
  419. arbitrary reinstallation of /RAM could bring the system down.
  420.  
  421.  
  422. Further Reference
  423. _____________________________________________________________________________
  424.   o  ProDOS 8 Technical Reference Manual
  425.   o  AppleShare Programmer's Guide for the Apple IIGS (APDA)
  426.   o  ProDOS 8 Technical Note #15, How ProDOS 8 Treats Slot 3
  427.   o  ProDOS 8 Technical Note #20, Mirrored Devices and SmartPort
  428.   o  ProDOS 8 Technical Note #23, ProDOS 8 Changes and Minutia
  429.   o  ProDOS 8 Technical Note #26, Polite Use of Auxiliary Memory
  430.  
  431.